package com.weng.cloud.service8881.postman;

import com.google.common.collect.Maps;
import com.weng.cloud.commons.base.ObjectUtil;
import com.weng.cloud.service8881.mapStruct.dto.SourceDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.ApplicationScope;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

/**
 * @Author: weng
 * @Date: 2022/6/28
 * @Description: com.weng.cloud.service8881.postman
 */
@RestController
@RequestMapping("/postman")
public class PostmanController {

    @RequestMapping(value = "/getCookie", method = RequestMethod.GET)
    public Map<String, Object> getCookie(@RequestParam(defaultValue = "false") boolean isCookie) {
        Map<String, Object> map = Maps.newHashMap();
        if(isCookie){
            map.put("cookie","weng's cookie");
        }
        map.put("kd",1.5);
        return map;
    }

    @Resource
    ApplicationContext applicationContext;

    @RequestMapping(value = "/verifyCookie", method = RequestMethod.POST)
    public String verifyCookie(@RequestHeader(defaultValue = StringUtils.EMPTY) String cookie){
//        applicationContext.getBean();
        return ObjectUtil.isStringNullOrBlank(cookie) || StringUtils.equalsIgnoreCase(cookie, "null") ? "妹根了" : "有根！";
    }
}
